Skip to content

Add Cooperative Groups double buffered tile example#486

Open
j-stephan wants to merge 1 commit into
amd-stagingfrom
jstephan/cooperative-groups
Open

Add Cooperative Groups double buffered tile example#486
j-stephan wants to merge 1 commit into
amd-stagingfrom
jstephan/cooperative-groups

Conversation

@j-stephan

Copy link
Copy Markdown
Contributor

Motivation

In ROCm 7.14, we introduced new Cooperative Groups features. This example demonstrates how to use memcpy_async.

Technical Details

Not supported for HIP SDK or CUDA.

Test Plan

Tested locally on gfx1100 lab machine.

Test Result

Works.

Added/Updated documentation?

  • Yes
  • No, does not apply to this PR.

Included Visual Studio files?

  • Yes
  • No, does not apply to this PR.

Submission Checklist

Signed-off-by: Jan Stephan <jan.stephan@amd.com>
@j-stephan
j-stephan requested a review from zichguan-amd July 17, 2026 12:41
@j-stephan j-stephan self-assigned this Jul 17, 2026
@j-stephan
j-stephan requested review from a team as code owners July 17, 2026 12:41

@randyh62 randyh62 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Comment on lines +10 to +12
The async load of the next tile is issued into the other buffer while the current tile is consumed,
and a split barrier separates the moment a thread has finished reading a buffer from the moment the
block guarantees that every thread is done. The kernel applies the element-wise operation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The async load of the next tile is issued into the other buffer while the current tile is consumed,
and a split barrier separates the moment a thread has finished reading a buffer from the moment the
block guarantees that every thread is done. The kernel applies the element-wise operation
The async load of the next tile is issued into the second buffer while the current tile is consumed.
A split barrier separates the moment a thread has finished reading a buffer from the moment the
block guarantees that every thread is done. The kernel applies the element-wise operation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second sentence could be a little more clear as to the split barrier separating the two moments: the moment the thread reads the buffer, and the moment all threads have completed the operation.

## Description

This program showcases a double-buffered tile load pipeline built from two cooperative groups
APIs: the group-collective `cooperative_groups::memcpy_async` and the split barrier

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the term spilt barrier well understood? Should it be defined here at the start?

Comment on lines +26 to +28
This example targets the AMD/HIP (ROCm) backend: the NVIDIA path of
`<hip/cooperative_groups/memcpy_async.h>` is not yet implemented (the header carries a TODO for it),
and it requires a ROCm version recent enough to ship that public header.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This example targets the AMD/HIP (ROCm) backend: the NVIDIA path of
`<hip/cooperative_groups/memcpy_async.h>` is not yet implemented (the header carries a TODO for it),
and it requires a ROCm version recent enough to ship that public header.
This example targets the AMD/HIP (ROCm) backend,
and it requires a ROCm version recent enough to ship that public header.


### Application flow

1. A number of compile-time constants define the tile size (also the block size), the number of

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. A number of compile-time constants define the tile size (also the block size), the number of
1. A number of compile-time constants define the tile size and block size, the number of

Comment on lines +55 to +58
sizeof(float)`). The copy is asynchronous and HIP exposes no separate wait handle, so its
completion is enforced by a following group barrier (`block.sync()` or the split barrier's
`barrier_wait`). On hardware or compilers without the asynchronous LDS builtins it falls back to a
correct traditional per-thread copy, so it always produces correct results.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sizeof(float)`). The copy is asynchronous and HIP exposes no separate wait handle, so its
completion is enforced by a following group barrier (`block.sync()` or the split barrier's
`barrier_wait`). On hardware or compilers without the asynchronous LDS builtins it falls back to a
correct traditional per-thread copy, so it always produces correct results.
sizeof(float)`). The copy is asynchronous and HIP exposes no separate wait handle, so the copy
completion is enforced by a following group barrier (`block.sync()` or `barrier_wait`).
On hardware or compilers without the asynchronous LDS builtins it falls back to a
correct traditional per-thread copy, so it always produces correct results.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear to me what "it" refers to in "it falls back to"

completion is enforced by a following group barrier (`block.sync()` or the split barrier's
`barrier_wait`). On hardware or compilers without the asynchronous LDS builtins it falls back to a
correct traditional per-thread copy, so it always produces correct results.
- The split barrier decomposes a block barrier into two phases. `thread_block::barrier_arrive`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph (or bullet) would be very helpful at the start of this topic for those who might be learning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants